﻿//smileys.js
     
     // List of names of smileys 
      listSmileName=new Array(  
      "ahah1","confirm","zzz","confuse1","confuse2","cool","cry4","cry1","cry2","cry3","devil","fun","gun1","hands",
      "kiss1","kiss2","lol1","lol2","lol3","love2","nono","ooh","happy1","happy2","yes");
      
      //I put the gif in the folder .. /Messages/smile/ and the name of smile coincides with the names of gif 
      function listImage(){      
            listSmile =new Array();
             for(var i = 0; i<listSmileName.length;i++)
                 listSmile[i] ="<img src='../Messages/smile/"+listSmileName[i]+".gif' /> ";
            return listSmile;
     }
      
      //replacing the code of smileys "(namesmile)" associated with tag img 
      function Addsmile(){
    if((document.getElementById("ctl00_ContentHomePage_textMessPreSmile"))== null)return;
    if((document.getElementById("ctl00_ContentHomePage_DivViewTextPM"))== null)return;
       
       divEl = document.getElementById("ctl00_ContentHomePage_textMessPreSmile").value;

        repl = divEl;
      var listimg = listImage(); 
      for(var i = 0; i<listSmileName.length;i++){
      var tmp = "\\("+listSmileName[i]+"\\)";
      reg = new RegExp(tmp,"g")
      repl = repl.replace(reg, listimg[i]);
        }
        
     reg = new RegExp("\\(danieleguiloa\\)","g");
      repl = repl.replace(reg, "<img src='../Messages/smile/danieleloagui.gif' />" );
    // because I did not want that allows the sender could insert code html I used a
    // code "(breakbrspace)" which I defined, to create the break;
         reg = new RegExp("\\(breakbrspace\\)","g")
      repl = repl.replace(reg, "<br />");

      document.getElementById("ctl00_ContentHomePage_DivViewTextPM").innerHTML = repl;
      }
      
      //create the list for the selection of smileys in div id SmileysContent 
     function addListSmile(){
         if((document.getElementById("SmileysContent"))== null)return;
           var listSmileTable = document.getElementById("SmileysContent");
         var result = "<table style='border:solid 1px;'>";
         idx = 0;
         var ListImg = listImage();
              for(var  i = 0;i<5;i++){
                result += "<tr>";
                //create a table 5x5
               for(var  j = 0;j<5;j++){            
                 result += "<th onclick=\"thClick('"+listSmileName[idx]+"');\" style='border:Solid 1px #9fd306;'>";
                      result +=   ListImg[idx];                  
                      result += "</th>";                    
                      idx++;
        }
              result += "</th>";
     }
     result += "</table>";

     listSmileTable.innerHTML = result;
     };
     
     //add the smile code in the text with id ctl00_ContentHomePage_TextBoxTextMess 
     function thClick(id){
      var text = document.getElementById("ctl00_ContentHomePage_TextBoxTextMess");
      text.value+="("+id+")";
       //I used jquery to hide the div smileys selection after selection
      $("div#SmileysContent").hide("fast");
     };